package com.xh.bussiness.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xh.bussiness.system.bean.dto.BusinessAttrConfigBean;
import com.xh.bussiness.system.bean.request.BusinessAttrConfigRequest;
import com.xh.bussiness.system.dao.BusinessAttrConfigMapper;
import com.xh.bussiness.system.model.BusinessAttrConfig;
import com.xh.bussiness.system.service.IBusinessAttrConfigService;
import com.xh.core.bean.XhPage;
import com.xh.core.service.impl.BaseServiceImpl;
import com.xh.core.util.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 业务属性配置 服务实现类
 * </p>
 *
 * @author Pitt zhang
 * @since 2019/2/27
 */
@Service
public class BusinessAttrConfigServiceImpl extends BaseServiceImpl<BusinessAttrConfigMapper, BusinessAttrConfig> implements IBusinessAttrConfigService {
    @Override
    public XhPage queryBusinessAttrConfigPage(XhPage page, BusinessAttrConfigRequest bean) {
        QueryWrapper qw=new QueryWrapper<BusinessAttrConfig>();
        //拼装条件
        qw=prepareParams(bean, qw);
        return (XhPage) this.selectPage(page,qw,BusinessAttrConfigBean.class);
    }

    @Override
    public List queryBusinessAttrConfig(BusinessAttrConfigRequest bean) {
        QueryWrapper qw=new QueryWrapper<BusinessAttrConfig>();
        //拼装条件
        qw=prepareParams(bean, qw);
        return this.selectList(qw,BusinessAttrConfigBean.class);
    }

    /**
     * 准备条件
     * @param bean
     * @param qw
     */
    private QueryWrapper prepareParams(BusinessAttrConfigRequest bean, QueryWrapper qw) {
        if(bean.getIds()!=null&&bean.getIds().length>0){
            qw.in("id",bean.getIds());
        }
        if(!StringUtils.isEmpty(bean.getCode())){
            qw.eq("code",bean.getCode().trim());
        }
        if(!StringUtils.isEmpty(bean.getName())){
            qw.eq("name",bean.getName().trim());
        }
        return qw;
    }
}
